package it.blueocean.acanto.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;

public enum UserRole
{
	ROLE_ADMIN("Administrator"), ROLE_USER("Standard User"), ROLE_GUEST("Ospite");
	
	private final String valore;

	UserRole(String valore)
	{
		this.valore = valore;
	}

	public static List<UserRole> getListUserRole()
	{
		return new ArrayList<UserRole>(Collections.synchronizedSet(EnumSet.allOf(UserRole.class)));
	}
	
	public static List<String> getListStringUserRoleEnumValues()
	{
		List<String> resultList = new ArrayList<String>();
		List<UserRole> list = UserRole.getListUserRole();
		for (UserRole userRole : list)
		{
			resultList.add(userRole.getValore());
		}
		return resultList;
	}
	
	
	public String getValore()
	{
		return valore;
	}
	
	public static int getIndex(String value)
	{
		List<UserRole> list = getListUserRole();
		for (UserRole item : list)
		{
			if(item.valore.equalsIgnoreCase(value))
				return item.ordinal();
		}
		return -1;
	}
	
	public static UserRole getFromValue(String value)
	{
		List<UserRole> list = getListUserRole();
		for (UserRole item : list)
		{
			if(item.valore.equalsIgnoreCase(value))
				return item;
		}
		return null;
	}
}
